<?php

namespace Framework\Middleware;

use Framework\Session;

/**
 * 认证授权中间件类
 */
class Authorise
{
    /**
     * 检查用户是否已经认证
     */
    public function isAuthenticated()
    {
        return Session::has('user');
    }
    /**
     * 处理用户的请求
     */
    public function handle($role)
    {
        if ($role === 'guest' && $this->isAuthenticated()) {
            return redirect('/');
        } elseif ($role === 'auth' && !$this->isAuthenticated()) {
            return redirect('/auth/login');
        }
    }
}
